
<div style="POSITION: relative" id="content">
  <h3>使用easyUI 格式化datagrid列</h3>
  <div id="article_content" class="article_content">
    <p>以下示例&#26684;式化在easyui DataGrid 里的列数据,和使用自定义列formatter ,如果价&#26684;小于20就将文本变为红色.</p>
    <p><img src="documentation/images/1344565586_8829.png" alt=""><br>
    </p>

    <p>&#26684;式化一个DataGrid 列,我们需要设置formatter 属性它是一个函数,这个&#26684;式化函数包含三个参数:</p>
    <ul style="font-size:14px; font-family:Arial,Helvetica,'Nimbus Sans L',sans-serif; text-align:left">
      <li>value: 当前列对应字段&#20540;.</li>
      <li>row: 当前的row(行)记录数据.</li>
      <li>index: 当前的行下标.</li>
    </ul>
    <h4 style="font-size:16px; color:rgb(204,0,0); margin:10px 0px; font-family:Arial,Helvetica,'Nimbus Sans L',sans-serif; text-align:left"> 创建 DataGrid</h4>
    <pre name="code" class="html">&lt;table id=&quot;tt&quot; title=&quot;Formatting Columns&quot; class=&quot;easyui-datagrid&quot; style=&quot;width:550px;height:250px&quot;  
        url=&quot;data/datagrid_data.json&quot;  
        singleSelect=&quot;true&quot; iconCls=&quot;icon-save&quot;&gt;  
    &lt;thead&gt;  
        &lt;tr&gt;  
            &lt;th field=&quot;itemid&quot; width=&quot;80&quot;&gt;Item ID&lt;/th&gt;  
            &lt;th field=&quot;productid&quot; width=&quot;80&quot;&gt;Product ID&lt;/th&gt;  
            &lt;th field=&quot;listprice&quot; width=&quot;80&quot; align=&quot;right&quot; formatter=&quot;formatPrice&quot;&gt;List Price&lt;/th&gt;  
            &lt;th field=&quot;unitcost&quot; width=&quot;80&quot; align=&quot;right&quot;&gt;Unit Cost&lt;/th&gt;  
            &lt;th field=&quot;attr1&quot; width=&quot;100&quot;&gt;Attribute&lt;/th&gt;  
            &lt;th field=&quot;status&quot; width=&quot;60&quot; align=&quot;center&quot;&gt;Stauts&lt;/th&gt;  
        &lt;/tr&gt;  
    &lt;/thead&gt;  
&lt;/table&gt;  </pre>
    注意<span style="font-family:Arial,Helvetica,'Nimbus Sans L',sans-serif; font-size:14px; text-align:left">&nbsp;'listprice'字段有一个<span style="font-family:Arial,Helvetica,'Nimbus Sans L',sans-serif; font-size:14px; text-align:left">&nbsp;'formatter'属性这个指明&#26684;式化函数.</span></span>

    <h4 style="font-size:16px; color:rgb(204,0,0); margin:10px 0px; font-family:Arial,Helvetica,'Nimbus Sans L',sans-serif; text-align:left"> 写&#26684;式化函数</h4>
    <pre name="code" class="javascript">function formatPrice(val,row){  
    if (val &lt; 20){  
        return '&lt;span style=&quot;color:red;&quot;&gt;('+val+')&lt;/span&gt;';  
    } else {  
        return val;  
    }  
}  </pre>
    <h4 style="font-size:16px; color:rgb(204,0,0); margin:10px 0px; font-family:Arial,Helvetica,'Nimbus Sans L',sans-serif; text-align:left"> 下载 EasyUI示例代码:</h4>
    <div style="font-size:14px; font-family:Arial,Helvetica,'Nimbus Sans L',sans-serif; text-align:left; padding-left:50px"> <a href="http://www.jeasyui.com/tutorial/datagrid/downloads/easyui-datagrid7-demo.zip" target="_blank" class="download-link" style="color:rgb(0,0,255)">easyui-datagrid-demo.zip</a></div>
    <br>
  </div>
</div>
<SCRIPT type=text/javascript>
	dp.SyntaxHighlighter.ClipboardSwf = 'documentation/js/clipboard.swf'/*tpa=http://jeasyui.com/SyntaxHighlighter/Scripts/clipboard.swf*/;
	dp.SyntaxHighlighter.HighlightAll('code');
</SCRIPT>